package org.common.akka.actor;

import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.AbstractBehavior;
import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.Receive;
import akka.actor.typed.javadsl.ReceiveBuilder;
import lombok.extern.slf4j.Slf4j;
import org.common.akka.message.BaseMsg;

@Slf4j
public abstract class BaseActor extends AbstractBehavior<BaseMsg> {
    public BaseActor(ActorContext<BaseMsg> context) {
        super(context);
    }

    @Override
    public Receive<BaseMsg> createReceive() {
        ReceiveBuilder<BaseMsg> builder = newReceiveBuilder();
        onCreateReceive(builder);
        builder.onMessage(BaseMsg.class, this::onBaseMsg);
        return builder.build();
    }

    protected void onCreateReceive(ReceiveBuilder<BaseMsg> builder){}

    private Behavior<BaseMsg> onBaseMsg(BaseMsg msg) {
        log.info("receive base msg. {}", msg.toString());
        return this;
    }
}
